define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'systemconfig/index' + location.search,
                    add_url: 'systemconfig/add',
                    edit_url: 'systemconfig/edit',
                    // del_url: 'systemconfig/del',
                    multi_url: 'systemconfig/multi',
                    import_url: 'systemconfig/import',
                    table: 'system_config',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        // {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        { field: 'tab', title: __('Tab'), searchList: { "1": __('Tab 1'), "2": __('Tab 2'), "3": __('Tab 3'), "4": __('Tab 4'), "5": __('Tab 5') }, formatter: Table.api.formatter.normal },
                        { field: 'title', title: __('Title'), operate: 'LIKE' },
                        {
                            field: 'value', title: __('Value'), formatter: function (value, row, index) {
                                if (row.type == 'bool') {
                                    return row.value == 1 ? __('开') : __('关');
                                } else if (row.type == 'int' || row.type == 'string') {
                                    return row.value;
                                } else if (row.type == 'image') {
                                    return '<a href="javascript:"><img class="img-sm img-center" src="' + row.value + '"></a>';
                                }
                            }
                        },
                        // { field: 'type', title: __('Acct_id') },
                        { field: 'acct.admin.nickname', title: __('平台'), operate: false },
                        { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
